﻿using System;
using System.ComponentModel.Composition;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Unity;
using Silverlight.Weblog.Client.DAL.Events;
using Silverlight.Weblog.Client.DAL.Services.Interfaces;
using Silverlight.Weblog.Common.IoC;
using Silverlight.Weblog.Server.DAL;

namespace Silverlight.Weblog.Client.DAL.Services
{
    public class GoToHomePageService : IGoToHomePageService
    {
        [Dependency]
        public IDBContextContainer DBContextContainer { get; set; }


        public void NavigateToHomePage()
        {
            DBContextContainer.Current
                   .Load(DBContextContainer.Current.GetHomePageBlogPostsQuery(),
                         initial => IoC.Get<IEventAggregator>().GetEvent<GoToBlogPostsEvent>().Publish(initial.Entities.ToList())
                         , null);
            

            IoC.Get<IEventAggregator>().GetEvent<ChangingTitleEvent>().Publish("Home Page");
        }
    }
}
